package edu.towson.cosc716.Commands;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Queue;

import edu.towson.cosc716.interfaces.Command;
import edu.towson.cosc716.models.Chef;
import edu.towson.cosc716.models.Constants;
import edu.towson.cosc716.models.Customer;
import edu.towson.cosc716.models.InformationAggregator;
import edu.towson.cosc716.models.Order;

// TODO: Auto-generated Javadoc
/**
 * The Class ViewReportCmd.
 */
public class ViewReportCmd implements Command {

	/** The report name. */
	private String reportName;
	
	/** The info aggregator. */
	private InformationAggregator infoAggregator;
	
	/**
	 * Instantiates a new view report cmd.
	 *
	 * @param repName the rep name
	 * @param infoAgg the info agg
	 */
	public ViewReportCmd(String repName, InformationAggregator infoAgg) {
		this.reportName = repName;
		this.infoAggregator = infoAgg;
	}
	
	/* (non-Javadoc)
	 * @see edu.towson.cosc716.interfaces.Command#execute()
	 */
	@Override
	public Object execute() {
		List<String> reportToReturn = new ArrayList<String>();
		if (this.reportName.equals(Constants.Reports.GET_ORDERS_IN_KITCHEN)) {
			Integer ordersInKitchen = this.infoAggregator.kitchen.size();
			if (ordersInKitchen>0) {
				Iterator it = this.infoAggregator.kitchen.entrySet().iterator();
			    while (it.hasNext()) {
			        Map.Entry<Chef,Order> pairs = (Map.Entry)it.next();
			        reportToReturn.add(pairs.getKey().getName() + "," + 
			        		this.infoAggregator.menu.find(pairs.getValue().getMenuItemId()).getName());
			    }
				reportToReturn.add("Total Orders In Kitchen, "+ordersInKitchen.toString());
			}
			
			
		} else if (this.reportName.equals(Constants.Reports.GET_KITCHENQ_REPORT)) {
			Integer ordersInQ = this.infoAggregator.orders.getList().size();
			if (ordersInQ > 0) {
				ListIterator<Order> itr = this.infoAggregator.orders.getList().listIterator();
				Order currOrderInQ = null;
				while (itr.hasNext()) {
					currOrderInQ = (Order)itr.next();
					reportToReturn.add("Table # "+currOrderInQ.getTableId() + "," +
							this.infoAggregator.menu.find(currOrderInQ.getMenuItemId()) );
				}
			}
			
			
			
		} else if (this.reportName.equals(Constants.Reports.GET_SEATINGQ_REPORT)) {
			Integer qSize = this.infoAggregator.seatingQueue.size();
			if (qSize>0) {
				ListIterator<Customer> itr = this.infoAggregator.seatingQueue.listIterator();
				Customer currCustInQ = null;
				
				int totalCustomersInQ = 0;
				int totalPartiesInQ = 0;
				while (itr.hasNext()) {
					currCustInQ = (Customer)itr.next();
					reportToReturn.add(currCustInQ.getPartyName() + "," + currCustInQ.getPartyCount());
					totalCustomersInQ += currCustInQ.getPartyCount();
					totalPartiesInQ++;
				} 
				reportToReturn.add("Total Customers In Queue, "+totalCustomersInQ);
				reportToReturn.add("Total Parties In Queue, "+totalPartiesInQ);
			} else reportToReturn.add("");
			
			
		} // else if (add more reports here)
		
		return reportToReturn;
	}

}
